<template>
  <div class="item-one" ref="itemOne">
    <div class="title">
      <span>分账商户查询</span>
      <div>
        <el-button
          type="primary"
          v-if="userinfo.rolesId == '5'"
          @click="addAccount()"
          >创建账户</el-button
        >
      </div>
    </div>
    <div class="container">
      <div class="screeningBox">
        <div class="leftBox">
                   <div class="leftitem">
            <div class="block">
                <el-date-picker
              v-model="date"
              type="datetimerange"
              :picker-options="pickerOptions"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :clearable="false"
              :default-time="['00:00:00', '23:59:59']"
            >
            </el-date-picker>
            </div>
          </div>
      <!-- <div class="leftitem">
           <el-input v-model="TradingMerchantName" placeholder="交易商户号/交易商户名" style="width:250px;"></el-input>
           <el-input v-model="BusinessAccountName" placeholder="手续费承担方" style="width:250px;"></el-input>
          </div> -->
        </div>
        <div class="rightBox">
          <div class="rightitem" v-if="userinfo.rolesId != 4">
            <el-form ref="conditions" :model="conditions">
              <el-select
                v-if="
                  userinfo.rolesId == 1 ||
                  userinfo.rolesId == 8 ||
                  userinfo.rolesId == 9
                "
                v-model="conditions.servicelevel"
                placeholder="服务商级别"
                @change="servicelevel"
              >
                <el-option keys="1" label="一级服务商" value="1"></el-option>
                <el-option keys="2" label="二级服务商" value="2"></el-option>
              </el-select>
              <el-autocomplete
                v-if="
                  userinfo.rolesId == 1 ||
                  userinfo.rolesId == 8 ||
                  userinfo.rolesId == 2 ||
                  userinfo.rolesId == 9"
                class="widthp30"
                v-model.trim="conditions.servicename"
                :fetch-suggestions="querySearch"
                placeholder="服务商名称"
                @select="serviceid"
              ></el-autocomplete>
              <el-autocomplete
               v-if="userinfo.rolesId != 5" 
                class="widthp30"
                v-model.trim="conditions.BDname"
                :fetch-suggestions="BDname"
                placeholder="业务经理"
                @select="BDid"
              ></el-autocomplete>
            </el-form>
          </div> 
            <div class="rightitem">
            <el-form label-width="80px">
              <el-select v-model="channelId" placeholder="通道类型">
                <el-option
                  v-for="(value, index) in channelTypeList"
                  :key="index"
                  :label="value.channelname"
                  :value="value.id"
                ></el-option>
              </el-select>
           <el-input v-model="splitKeyWords" class="widthp30"  placeholder="商户号/商户名" ></el-input>
           <el-input v-model="walletNo" class="widthp30" placeholder="渠道商户号" ></el-input>
           <el-select v-model="splitPid" placeholder="商户类型" style="margin-top:10px;">
                <el-option label="分出方(母户)" value="-1"></el-option>
                <el-option label="接收方(子户)" value="1"></el-option>
              </el-select>
            </el-form>
          </div>
          <div class="rightitem">
            <el-button icon="el-icon-search" type="primary" @click="soso"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" type="primary" @click="reset"
              >重置</el-button
            >
          </div>
        </div>
      </div>
      <div class="statistical">
        <div class="statisticalitem">
          <div>总商户数</div>
          <div>
            <span class="red">{{ merchantsinfo.total }}</span> 家
          </div>
        </div>
        <div class="statisticalitem">
          <div>动销商户数</div>
          <div>
            <span class="red">{{ merchantsinfo.active }}</span> 家
          </div>
        </div>
      </div>
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="merchantarr"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          stripe
          :header-cell-style="tableHeaderColor"
        >
          <el-table-column
            align="center"
            type="index"
            width="60"
            label="序号"
          ></el-table-column>
          <el-table-column
           prop="name"
            label="商户名称?商户号"
           align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div class="position" v-if="scope.row.splitId == '-1'">交</div>
              <div
                class="position greens"
                v-if="scope.row.splitId != '-1' && scope.row.splitId"
              >
                分
              </div>
              <div>{{ scope.row.splitMerchantName }}</div>
              <div>
                {{ scope.row.splitMerchantNo }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
           prop="channelName"
            label="分账通道"
            align="center"
          />
          <el-table-column
           prop="splitPid"
            label="分账标识"
            align="center"
          >
            <template slot-scope="scope">
               <el-tag v-if=" scope.row.splitPid == '-1' " type="warning"> 分出方 </el-tag>
               <el-tag v-else  type="success"> 接收方 </el-tag>
            </template>
          </el-table-column>
          <el-table-column
           prop="walletNo"
            label="渠道商户号"
            align="center"
          />
          <el-table-column
           prop="channelName"
            label="状态"
            align="center"
          >
          <template slot-scope="scope">
               <p> {{ scope.row.walletStatus == '0' ? '未开通' : '已开通'}} </p>
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="创建时间"
            align="center"
          ></el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            width="120"
          >
            <template slot-scope="scope">
              <!-- <el-button
                type="text"
                size="small"
                v-if="userinfo.rolesId == 1||userinfo.rolesId == 8"
                @click="AllocationConfiguration(scope.row)"
                :valu="scope.row.id"
                >配置</el-button> -->
                <el-button
                type="text"
                size="small"
                @click="joinmerchantsinfo(scope.row)"
                >详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            @current-change="handleCurrentChange"
            @size-change="sizechange"
            :current-page.sync="cur_page"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="combined"
          ></el-pagination>
        </div>
      </div>
      <br />
      <br />
      <!-- 配置弹窗 -->
         <el-dialog
        title="配置分账"
        :visible.sync="AllocationConfigurationstatus"
        width="46%"
        :close-on-click-modal="false"
      >
        <div>
          <div class="configurationItem"><span class="conWords">手续费承担方：</span><el-input v-model="splitFeeMchNo" placeholder="请输入商户号 "></el-input></div>
          <div class="configurationItem"><span class="conWords2">分账比例：</span><el-input style="width: 200px" v-model="splitRate" type="number" placeholder="请输入内容">   </el-input><span>%</span> </div>
          <div class="configurationItem"><span class="conWords2">分账手续费比例：</span><el-input style="width: 200px" v-model="splitFee" type="number" placeholder="请输入内容"></el-input><span>%</span> </div>
          <div class="configurationItem"><span class="conWords">单笔手续费：</span><el-input v-model="splitFeePer" type="number" placeholder="请输入内容"></el-input></div>
          <div class="configurationItem"><span class="conWords">通道商户号：</span><el-input v-model="mchId" placeholder="请输入内容"></el-input></div>
          <div class="configurationItem"><span class="conWords">通道商户key：</span><el-input v-model="mchKey" placeholder="请输入内容"></el-input></div>
          <div class="configurationItem"><span class="conWords">服务商机构号serv_no：</span><el-input v-model="serv_no" placeholder="请输入内容"></el-input></div>
          <div class="configurationItem"><span class="conWords">服务商appid：</span><el-input v-model="serv_appid" placeholder="请输入内容"></el-input></div>
          <div class="configurationItem"><span class="conWords">服务商rsaggo公钥：</span><el-input v-model="serv_rsa_public" placeholder="请输入内容"></el-input></div>
          <div class="configurationItem"><span class="conWords"> 服务商rsaggo私钥：</span><el-input v-model="serv_rsa_private" placeholder="请输入内容"></el-input></div>
          <div class="configurationItem"><span class="conWords">通道(平台) rsa公钥：</span><el-input v-model="plat_rsa_public" placeholder="请输入内容"></el-input></div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="AllocationConfigurationstatus = false">取消</el-button>
          <!-- @click="visible = false" -->
          <el-button type="primary" @click="configurationOK()">确定</el-button>
        </span>
      </el-dialog>

    </div>
  </div>
</template>

<script>
import {
  APIDivideAccountsConfiguration,
  getservice,
  getBD,
  getActiveCount,
  addshop,
  blockup,
  merchantremove,
  merchantenable,
  merchanttransfer,
  myMerchantExcel,
  getlabelTagList,
  getDimensionTagList,
  getChannelList,
  allmerchantlist,
  chainopen,
  chainclose,
  arealist,
  mcclist,
  APISplitAccountMerchantList,
  APISplitAccountMerchantStatistics,
  merchantlist,
  divideChannelList
} from "@/api/api";
import axios from "axios";
import bus from "../common/bus";
export default {
  name: "baseform",
  data: function () {
    return {
      AllocationConfigurationstatus:false,//配置弹窗状态
      splitStatus:{
         splitId:'',
      },
      configurationid:'',
      splitFeeMchNo:'',
      splitRate:'',
      splitFee:'',
      splitFeePer:'',
      mchId:'',
      mchKey:'',
      serv_no:'',
      serv_appid:'',
      serv_rsa_public:'',
      serv_rsa_private:'',
      plat_rsa_public:'',
      chengeqx: 0,
      oeminfo: {},
      tagsList: [],
      tableData: [],
      cur_page: 1,
      cur_size: 10,
      multipleSelection: [],
      visible: false,
      loading: true,
      changeBD: false,
      exxxx: false,
      visible1: false,
      setupshops: {
        type: "-1",
        openTime: "",
        closeTime: "",
        permissions: "",
        lines: "",
        pid: "-1",
        splitId:''
      },
      servicearr: [],
      servicearr1: [],
      BDarr: [],
      provincearr: [],
      cityarr: [],
      wx1arr: [],
      ids: [],
      wx1code: "",
      wx2arr: "",
      merchantarr: [],
      combined: 10,
      pageCount: "",
      merchantsinfo: "",
      shopname: "",
      shopid: "",
      date: "",
      merarr: [],
      addmendian: {
        name: "",
        phone: "",
        address: "",
        contact: "",
        contactphone: "",
        mchUniNo: "",
        wxMchId: "",
        wxAppid: "",
        udfType: "",
        udfAccount: "",
        bank: "",
        aliShopId: "",
        aliSpmerToken: "",
        alias: "",
        wxGoodsTag: "",
        ecnyTermId: "",
      },
      changeBDdata: {
        agent1: "",
        agent2: "",
        BDname: "",
      },
      conditions: {
        servicelevel: "",
        servicename: "",
        BDname: "",
        merchantsstate: "",
        merchantsno: "",
        province: "",
        provincecode: "",
        city: "",
        stardate: "",
        enddate: "",
        serviceid: "",
        BDid: "",
        wx1s: "",
        mchId:""
      },
      userinfo: {},
      payType: "", //支付方式
      channelId: "", //通道类型
      channelTypeList: [],
      dimension: "", //选择维度
      tagname: "", //标签名
      label_all: [], //标签模糊查询
      tagId: "",
      walletNo:'',
      splitPid:'',
      splitKeyWords:null,//分账商户号/分账商户名
      TradingMerchantName:'',//交易商户号/交易商户名
      BusinessAccountName:'',//手续费承担方商户号/手续费承担方商户名
        tarminal: {
        payLogo: "",
        shopName: "",
        marid:''
      },
      pickerOptions: {
        disabledDate(time) {
          let nowDate = new Date();
          let date = {
            year: nowDate.getFullYear(),
            month: nowDate.getMonth() + 1,
            date: nowDate.getDate(),
          };
          let timeDate =
            date.year + "-" + date.month + "-" + date.date + " 23:59:59";
          let times = new Date(timeDate).getTime();
          return time.getTime() > times;
        },
      },
    };
  },
  created() {
    this.userinfo = JSON.parse(sessionStorage.getItem("userInfo"));
    if (sessionStorage.getItem("oeminfo") != "null") {
      this.oeminfo = JSON.parse(sessionStorage.getItem("oeminfo"));
    }
  

    // 根据角色区别模糊搜索内容
    if (this.userinfo.rolesId == 2 || this.userinfo.rolesId == 3) {
      getservice({
        type: 2,
        parentid: this.userinfo.fid,
      }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.servicearr.push({
            value: res.data.rows[i].agentname,
            id: res.data.rows[i].id,
          });
        }
      });
      this.getBD(this.userinfo.fid);
    } else {
      this.getBD();
    }
    this.province();
    this.wx1();
    this.SplitAccountMerchantList();
    if (this.userinfo.rolesId == 2) {
      this.conditions.servicelevel == 2;
    } else if (this.userinfo.rolesId == 1) {
      this.conditions.servicelevel == 1;
    }
    this.getChannelList();
    // let _this = this
    //  bus.$on('tags', msg => {
    //    console.log(msg)
    //    _this.tagsList = msg
    // })
  },
  methods: {

    //配置弹窗按钮
    AllocationConfiguration(val){
      this.configurationid = val.id
      this.AllocationConfigurationstatus=true
    },
    configurationOK(){
      if(this.splitFeeMchNo==''){
          this.$message({
          message: '请输入手续费承担方',
          type: 'warning'
        });
      }else if(this.splitRate==''){
          this.$message({
          message: '请输入分账比例',
          type: 'warning'
        });
      }else if(this.splitFee==''){
          this.$message({
          message: '请输入分账手续费比例',
          type: 'warning'
        });
      }else if(this.splitFeePer==''){
          this.$message({
          message: '请输入单笔手续费',
          type: 'warning'
        });
      }else{
          APIDivideAccountsConfiguration({
      id:this.configurationid,
      splitFeeMchNo:this.splitFeeMchNo,
      splitRate:this.splitRate,
      splitFee:this.splitFee,
      splitFeePer:this.splitFeePer,
      mchId:this.mchId,
      mchKey:this.mchKey,
      serv_no:this.serv_no,
      serv_appid:this.serv_appid,
      serv_rsa_public:this.serv_rsa_public,
      serv_rsa_private:this.serv_rsa_private,
      plat_rsa_public:this.plat_rsa_public,
      }).then((res) => {
        if (res.code == 200) {
          // loading.close();
          this.$message({
            message: "配置成功",
            type: "success",
          });
          this.AllocationConfigurationstatus = false;
          // console.log('this.AllocationConfigurationstatus',this.AllocationConfigurationstatus);
          this.refresh();
        } else {
          this.$message.error(res.message);
          loading.close();
        }
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
        }
      });
      }
      

    },
    //处理列表数据
    dealListDate(array){
      for(let i=0;i<array.length;i++){
        let obj=array[i]
        if(!obj.splitRate) continue
        if(obj.splitRate){
          obj.splitRate=obj.splitRate+'%'
        }
         obj.tradeMerchantNo?this.splitStatus.splitId='0':this.splitStatus.splitId='-1'
        let obj1=  Object.assign( obj,this.splitStatus)
          // console.log('this.splitId',obj1);
      }
      return array
    },
    addAccount(){
      this.$router.push("/addMerchant");
    },
    defaulMerchantListData(res){

      if(res.data instanceof Array) {
        this.merchantarr =this.dealListDate( res.data)
        }else{
        this.merchantarr = []
      }

      if(res.pageInfo){
              this.combined = res.pageInfo.recordCount;
              this.pageCount = res.pageInfo.pageCount;
      }else{
              this.combined =0;
              this.pageCount =0;
      }
              
    },
    //修改thead 背景色
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background-color: #F0F0F0;font-weight: 500;font-size:14px;color:#000;";
      }
    },
    // 刷新
    refresh() {
      // this.$router.replace({
      //   path: "/refresh",
      //   query: {
      //     t: Date.now()
      //   }
      // });
      this.loading = true;
      this.SplitAccountMerchantList(this.conditions.servicelevel);
    },
    renderheader(h, { column, $index }) {
      return h("span", {}, [
        h("span", {}, column.label.split("?")[0]),
        h("br"),
        h("span", {}, column.label.split("?")[1]),
      ]);
    },
    // 分页导航
    handleCurrentChange(val) {
      this.cur_page = val;
      console.log(this.conditions.servicelevel,78879)
      this.SplitAccountMerchantList(this.conditions.servicelevel);
      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    // 分页数量
    sizechange(val) {
      this.cur_size = val;

      this.SplitAccountMerchantList(this.conditions.servicelevel);

      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    //多选框
    handleSelectionChange(val) {
      // console.log(val);
      this.multipleSelection = val;
    },
    // joinmerchantsinfo(val) {
    //   this.$router.push({
    //     path: "/merchantsinfo",
    //   });
    //   sessionStorage.setItem("merchants_id", JSON.stringify(val.id));
    //   sessionStorage.setItem(
    //     "merchants_merchantName",
    //     JSON.stringify(val.merchantName)
    //   );
    // },
    //  重置
    reset() {
      this.walletNo = ''
      this.splitPid = ''
      this.splitKeyWords=null,//分账商户号/分账商户名
      this.TradingMerchantName='',//交易商户号/交易商户名
      this.BusinessAccountName='',//手续费承担方商户号/手续费承担方商户名
      this.tarminal.marid = "";
      this.date = "";
      this.conditions.servicelevel = "";
      this.conditions.servicename = "";
      this.conditions.BDname = "";
      this.conditions.merchantsstate = "";
      this.conditions.merchantsno = "";
      this.conditions.mccId = "";
      this.conditions.areaId = "";
      this.conditions.province = "";
      this.conditions.city = "";
      this.conditions.wx1s = "";
      this.conditions.stardate = "";
      this.conditions.enddate = "";
      this.conditions.serviceid = "";
      this.conditions.BDid = "";
      this.conditions.contactName = "";
      this.wx1code = "";
      this.cur_page = 1;
      this.dimension = "";
      this.tagname = "";
      this.tagId = "";
      this.payType = "";
      this.channelId = "";
      this.conditions.mchId='';
      this.soso()
    },
    // 搜索
    soso() {
      if (
        this.date == null ||
        this.date.length == 0 ||
        this.date == undefined
      ) {
        this.date = [];
      }
      this.cur_page = 1;
      // if (this.channelType !== "" && this.payType == "") {
      //   this.$message.error("请先选择支付方式");
      //   return false;
      // }
      // if (this.payType !== "" && this.channelType == "") {
      //   this.$message.error("请选择通道类型");
      //   return false;
      // }
      this.loading = true;
      if (!this.conditions.servicename) {
        this.conditions.serviceid = "";
      }
      if (!this.conditions.BDname) {
        this.conditions.BDid = "";
      }
      if (this.conditions.servicelevel == 1) {
        this.SplitAccountMerchantList("1");
      } else if (this.conditions.servicelevel == 2) {
        this.SplitAccountMerchantList("2");
      } else {
        this.SplitAccountMerchantList("2");
      }
    },
    getChannelList() {
      divideChannelList({splitType: 1}).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          this.channelTypeList = res.data.rows;
        } else if (res.code == 500) {
          this.$message.error(res.message);
        }
      });
    },
    // 服务商名称
    querySearch(queryString, cb) {
      let servicearr = this.servicearr;
      let results = queryString
        ? servicearr.filter(this.createFilter(queryString))
        : servicearr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    // 切换BD服务商名称
    querySearch1(queryString, cb) {
      let servicearr = this.servicearr1;
      let results = queryString
        ? servicearr.filter(this.createFilter(queryString))
        : servicearr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    // 二级服务商
    querySearch2(queryString, cb) {
      let servicearr = this.servicearr2;
      let results = queryString
        ? servicearr.filter(this.createFilter(queryString))
        : servicearr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    // 总分店
    querySearch3(queryString, cb) {
      let merarr = this.merarr;
      let results = queryString
        ? merarr.filter(this.createFilter(queryString))
        : merarr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    // 根据一级查2级
    serviceid1(item) {
      this.servicearr2 = [];
      this.changeBDdata.agent2 = "";
      this.changeBDdata.BDname = "";
      getservice({
        type: 2,
        parentid: item.id,
      }).then((res) => {
        for (var i = 0; i < res.data.rows.length; i++) {
          this.servicearr2.push({
            value: res.data.rows[i].agentname,
            id: res.data.rows[i].id,
          });
        }
      });
      this.conditions.agent1Id = item.id;
    },
    // 获取2级
    serviceid2(item) {
      this.changeBDdata.agent2Id = item.id;
      this.changeBDdata.BDname = "";
      this.getBD(item.id);
    },
    BDid1(item) {
      this.changeBDdata.BDid = item.id;
    },
    // 业务经理
    BDname(queryString, cb) {
      let BDarr = this.BDarr;
      let results = queryString
        ? BDarr.filter(this.createFilter(queryString))
        : BDarr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) !==
          -1
        );
      };
    },
    BDid(item) {
      this.conditions.BDid = item.id;
    },
    serviceid(item) {
      this.conditions.serviceid = item.id;
      this.getBD(item.id);
    },
    // 服务商级别
    servicelevel(val) {
      this.servicearr = [];
      getservice({
        type: val,
      }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.servicearr.push({
            value: res.data.rows[i].agentname,
            id: res.data.rows[i].id,
          });
        }
      });
    },
    // 获取BD
    getBD(id) {
      this.BDarr = [];
      getBD({ agentid: id }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.BDarr.push({
            value: res.data.rows[i].name,
            id: res.data.rows[i].id,
          });
        }
      });
    },
    //获取省
    province() {
      arealist({
        level: 1,
      }).then((res) => {
        // console.log(res);
        this.provincearr = res.data;
      });
    },
    //获取市
    city(val) {
      let obj = {};
      obj = this.provincearr.find((item) => {
        //这里的userList就是上面遍历的数据源
        return item.id === val; //筛选出匹配数据
      });
      // console.log(obj);
      // this.conditions.provincecode = obj.code;
      this.conditions.areaId = obj.id;
      this.conditions.city = "";
      this.cityarr = "";
      arealist({
        level: 2,
        parent_id: val,
      }).then((res) => {
        // console.log(res);
        this.cityarr = res.data;
      });
    },
    city2(val) {
      this.conditions.areaId = val;
    },
    // 获取行业
    wx1(val) {
      mcclist({
        level: 1,
      }).then((res) => {
        this.wx1arr = res.data;
      });
    },
    // 行业二级
    wx2fun(val) {
      this.wx2arr = "";
      this.conditions.mccId = val;
      this.conditions.wx1s = "";
      mcclist({
        level: 2,
        parent_id: val,
      }).then((res) => {
        // console.log(res);
        this.wx2arr = res.data;
      });
    },
    // 监听行业2级
    wx3fun(val) {
      this.conditions.mccId = val;
    },
    // 商户列表
    SplitAccountMerchantList(level) {
      
      let sosolist = {};
      if (level == 1) {
        sosolist = {
          page: this.cur_page,
          size: this.cur_size,
          walletNo:this.walletNo,
          splitKeyWords:this.splitKeyWords,
          tradeKeyWords:this.TradingMerchantName,
          feeKeyWords:this.BusinessAccountName,
          channelId:this.channelId,
          splitPid:this.splitPid,
          agent1Id: this.conditions.serviceid,
          bdId: this.conditions.BDid,
          startTime: this.date[0],
          finishTime: this.date[1],
          // status: 1
          
        };
      } else if (level == 2) {
        sosolist = {
          page: this.cur_page,
          size: this.cur_size,
          walletNo:this.walletNo,
          splitKeyWords:this.splitKeyWords,
          splitPid:this.splitPid,
          tradeKeyWords:this.TradingMerchantName,
          feeKeyWords:this.BusinessAccountName,
          channelId:this.channelId,
          agent2Id: this.conditions.serviceid,
          bdId: this.conditions.BDid,
          startTime: this.date[0],
          finishTime: this.date[1],
          // status: 1
        };
      }else{
        sosolist = {
          page: this.cur_page,
          size: this.cur_size,
          walletNo:this.walletNo,
          splitKeyWords:this.splitKeyWords,
          splitPid:this.splitPid,
          tradeKeyWords:this.TradingMerchantName,
          feeKeyWords:this.BusinessAccountName,
          channelId:this.channelId,
          agent2Id: this.conditions.serviceid,
          bdId: this.conditions.BDid,
          startTime: this.date[0],
          finishTime: this.date[1],
          // status: 1
        };
      }
console.log(this.cur_page , sosolist)

    
      setTimeout(()=>{
        APISplitAccountMerchantList(sosolist)
        .then((res) => {
          switch (res.code) {
            case 405:
              sessionStorage.removeItem("token");
              this.$router.push("/login");
              break;
            case 200:
          this.defaulMerchantListData(res)
              this.loading = false;
              break;
            default:
              this.$message.error(res.message);
              this.loading = false;
             this.defaulMerchantListData(res)
              break;
          }
        });
      
      APISplitAccountMerchantStatistics(sosolist).then((res) => {
        // console.log(res);
        this.merchantsinfo = res.data;
      });
      },100)
    },
    joinmerchantsinfo(val){
      if(val.channelId == '16'){
        this.$router.push({
        path: "/detailMerchant?mid="+val.merchantId,
      });
      }else{
        this.$router.push({
        path: "/ElectronicAccountinfo",
      });
      sessionStorage.setItem("merchants_id", JSON.stringify(val.walletId));
      sessionStorage.setItem(
        "merchants_merchantName",
        JSON.stringify(val.merchantName)
      );
      }
      
    },
    
    // 获取总店
    allmerchantlist() {
      allmerchantlist({
        pid: "-1",
      }).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          // console.log(res);
          this.merarr = [];
          for (var i = 0; i < res.data.rows.length; i++) {
            this.merarr.push({
              value: res.data.rows[i].merchantName,
              id: res.data.rows[i].id,
            });
          }
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 选取总店
    dianming(val) {
      this.setupshops.pid = val.id;
    },
    //维度查询标签
    // dimension_menu(v){
    //   this.label_all = []
    //   getDimensionTagList({
    //     roleId: v
    //   }).then(res => {
    //     if(res.code == 405){
    //       sessionStorage. removeItem('token')
    //       this.$router.push('/login');
    //     }else if(res.code == 200){
    //       for(var i=0;i<res.data.length;i++){
    //         this.label_all.push({'value':res.data[i].tagName,'id':res.data[i].tagId})
    //       }
    //     }else{
    //       this.$message.error(res.message);
    //     }
    //   })
    // },
    //模糊查询商户名
    searchMerchantsList(queryString, cb) {
      
      let sosolist = {};
      sosolist = {
        page: 1,
        size: 20,
        merchantName: this.tarminal.marid,
      };
      merchantlist(sosolist).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          this.merchantarrlist = [];
          for (var i = 0; i < res.data.length; i++) {
            this.merchantarrlist.push({
              value: res.data[i].merchantName + " — " + res.data[i].merchantNo,
              id: res.data[i].id,
            });
          }
          let results = queryString
            ? this.merchantarrlist.filter(this.createFilter(queryString))
            : this.merchantarrlist;
          // 调用 callback 返回建议列表的数据
          cb(results);
        }
      });
    },
     getMerchantId(value){
      if(value==''){
        this.conditions.keywords=''
      }
    },
    marid(item) {
      this.conditions.keywords = item.id;
      this.tarminal.shopName = "";
    },
  
    // 打开增加门店
    addshop(val, id) {
      this.chengeqx = 0;
      this.visible = true;
      this.shopname = val;
      this.shopid = id;
      this.addmendian = {
        name: "",
        phone: "",
        address: "",
        contact: "",
        contactphone: "",
        mchUniNo: "",
        wxMchId: "",
        wxAppid: "",
        udfType: "",
        udfAccount: "",
        bank: "",
        alias: "",
        wxGoodsTag: "",
        ecnyTermId: "",
      };
    },
    // 增加门店
    addshopfun() {
      // console.log("ss", this.chengeqx);
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      addshop({
        merchantId: this.shopid,
        shopName: this.addmendian.name,
        shopTel: this.addmendian.phone,
        shopAddress: this.addmendian.address,
        managerName: this.addmendian.contact,
        managerMobile: this.addmendian.contactphone,
        terminalNoUni: this.addmendian.bank,
        aliShopId: this.addmendian.aliShopId,
        aliSpmerToken: this.addmendian.aliSpmerToken,
        alias: this.addmendian.alias,
        mchUniNo: this.addmendian.mchUniNo,
        wxMchId: this.addmendian.wxMchId,
        wxAppid: this.addmendian.wxAppid,
        udfType: this.addmendian.udfType,
        udfAccount: this.addmendian.udfAccount,
        canCancelCoupon: this.chengeqx,
        longpayPostId: this.addmendian.longpayPostId,
        longpayPublicKey: this.addmendian.longpayPublicKey,
        wxGoodsTag: this.addmendian.wxGoodsTag,
        ecnyTermId: this.addmendian.ecnyTermId,
        userId: 1,
        instno: sessionStorage.getItem("instNo"),
        key: sessionStorage.getItem("key"),
      }).then((res) => {
        if (res.code == 200) {
          loading.close();
          this.$message({
            message: "新增成功",
            type: "success",
          });
          this.visible = false;
          this.refresh();
        } else {
          this.$message.error(res.message);
          loading.close();
        }
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
        }
      });
    },
    // 停用门店
    blockups(val) {
      var that = this;
      this.$confirm("是否确定停用？如确定，该商户的支付将停用", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          blockup({}, val).then((res) => {
            // console.log(res);
            if (res.code == 405) {
              sessionStorage.removeItem("token");
              this.$router.push("/login");
            } else if (res.code == 200) {
              this.$message({
                message: "已停用",
                type: "success",
              });
              this.refresh();
            } else {
              this.$message.error(res.message);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 注销门店
    merchantremove(val) {
      this.$confirm("是否确定注销？如确定，该商户将被移除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          merchantremove({}, val).then((res) => {
            // console.log(res);
            if (res.code == 405) {
              sessionStorage.removeItem("token");
              this.$router.push("/login");
            } else if (res.code == 200) {
              this.$message({
                message: "已注销",
                type: "success",
              });
              this.refresh();
            } else {
              this.$message.error(res.message);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 启用商户
    merchantenable(val) {
      merchantenable({}, val).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          this.$message({
            message: "已启用",
            type: "success",
          });
          this.refresh();
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 新增门店
    addmerchants() {
      this.$router.push({
        path: "/addmerchants",
        query: {
          // no: val,
        },
      });
    },

    closetab() {
      // console.log(this.tagsList);
      for (var i = 0; i < this.tagsList.length; i++) {
        if (this.tagsList[i].title == "我的商户") {
          this.tagsList.splice(i, 1)[0];
          bus.$emit("tags", this.tagsList);
          this.$router.push("/audit");
        }
      }
    },

    // 打开切换bdbox
    changeBDbtn() {
      this.changeBDdata = {
        agent1: "",
        agent2: "",
        BDname: "",
      };
      if (this.multipleSelection.length > 0) {
        this.changeBD = true;
        getservice({
          type: 1,
        }).then((res) => {
          // console.log(res);
          for (var i = 0; i < res.data.rows.length; i++) {
            this.servicearr1.push({
              value: res.data.rows[i].agentname,
              id: res.data.rows[i].id,
            });
          }
        });
      } else {
        this.$message.error("请选择商户");
      }
    },
    // 确定切换
    changeBDok() {
      let that = this;
      // console.log(this.changeBDdata.BDid)
      this.ids = [];
      for (var item of this.multipleSelection) {
        this.ids.push(item.id);
      }
      if (this.changeBDdata.BDid) {
        axios
          .post(
            process.env.VUE_APP_BASE_URL +
              "/product/v31/api/merchant/transfer/" +
              this.changeBDdata.BDid,
            this.ids,
            {
              headers: {
                "Content-Type": "application/json",
                token: sessionStorage.getItem("token"),
              },
            }
          )
          .then(function (res) {
            // console.log(res);
            if (res.data.code == 405) {
              sessionStorage.removeItem("token");
              that.$router.push("/login");
            } else if (res.data.code == 200) {
              that.$message({
                message: "切换成功",
                type: "success",
              });
              that.refresh();
              that.changeBD = false;
            } else {
              that.$message.error(res.data.message);
            }
          });
      } else {
        this.$message.error("请选择业务经理");
      }
    },
    // 导出商户
    //导出
    merchantexcel() {
      let sosolist = {};
      if (this.conditions.servicelevel == 1) {
        sosolist = {
          agent1Id: this.conditions.serviceid,
          bdId: this.conditions.BDid,
          startTime: this.date[0],
          finishTime: this.date[1],
          mccId: this.conditions.mccId,
          areaId: this.conditions.areaId,
          // cityCode: this.conditions.city,
          // merchantMcc2: this.conditions.wx1s,
          // provinceCode: this.conditions.provincecode,
          keywords: this.conditions.merchantsno,
          status: this.conditions.merchantsstate,
          tagId: this.tagId,
          payType: this.payType,
          channelId: this.channelId,
        };
      } else if (this.conditions.servicelevel == 2) {
        sosolist = {
          agent2Id: this.conditions.serviceid,
          bdId: this.conditions.BDid,
          startTime: this.date[0],
          finishTime: this.date[1],
          mccId: this.conditions.mccId,
          areaId: this.conditions.areaId,
          // cityCode: this.conditions.city,
          // merchantMcc2: this.conditions.wx1s,
          // provinceCode: this.conditions.provincecode,
          keywords: this.conditions.merchantsno,
          status: this.conditions.merchantsstate,
          tagId: this.tagId,
          payType: this.payType,
          channelId: this.channelId,
        };
      } else {
        sosolist = {
          bdId: this.conditions.BDid,
          agent2Id: this.conditions.serviceid,
          startTime: this.date[0],
          finishTime: this.date[1],
          mccId: this.conditions.mccId,
          areaId: this.conditions.areaId,
          // cityCode: this.conditions.city,
          // merchantMcc2: this.conditions.wx1s,
          // provinceCode: this.conditions.provincecode,
          keywords: this.conditions.merchantsno,
          status: this.conditions.merchantsstate,
          tagId: this.tagId,
          payType: this.payType,
          channelId: this.channelId,
        };
      }
      this.exxxx = true;
      let i = 0;
      let time = setInterval(() => {
        if (i == 60) {
          loading.close();
          this.$message.error("请求超时");
          clearInterval(time);
        } else {
          i++;
        }
      }, 1000);
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      myMerchantExcel(sosolist).then((res) => {
        if (res.data.code == 405) {
          clearInterval(time);
          sessionStorage.removeItem("token");
          this.$router.push("/login");
          loading.close();
          this.exxxx = false;
        } else if (res.data.code == 200) {
          clearInterval(time);
          let elink = document.createElement("a");
          elink.download = "我的商户.xls";
          elink.href = res.data.data.replace("http://", "https://");
          elink.click();
          loading.close();
          this.exxxx = false;
        } else {
          clearInterval(time);
          this.$message.error(res.data.message);
          loading.close();
          this.exxxx = false;
        }
      });
    },
    // 打开总分店弹窗
    setupshop() {
      if (this.multipleSelection.length > 0) {
        this.visible1 = true;
        this.allmerchantlist();
      } else {
        this.$message.error("请选择商户");
      }
    },
    // 判断总店分店
    setupshopstype(e) {
      if (e == "-1") {
        this.setupshops.pid = "-1";
      }
    },
    // 确定总分店
    setupshopok() {
      let that = this;
      let dianarr = [];
      let marid = "";
      for (var item of this.multipleSelection) {
        dianarr.push(item.id);
      }
      marid = dianarr.join(",");
      chainopen({
        id: marid,
        openTime: that.setupshops.openTime,
        closeTime: that.setupshops.closeTime,
        limitFee: that.setupshops.lines,
        pid: that.setupshops.pid,
      }).then((res) => {
        if (res.code == 200) {
          that.$message({
            message: "开通成功",
            type: "success",
          });
        } else {
          that.$message.error(res.message);
        }
        this.visible1 = false;
        this.refresh();
        this.setupshops = {
          type: "-1",
          openTime: "",
          closeTime: "",
          permissions: "",
          lines: "",
          pid: "-1",
        };
      });
    },
    // 关闭总门店
    chainclose(id) {
      let that = this;
      this.$confirm("是否确定关闭？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          chainopen({
            id: id,
          }).then((res) => {
            if (res.code == 200) {
              that.$message({
                message: "已关闭总分店模式",
                type: "success",
              });
            } else {
              that.$message.error(res.message);
            }
            this.refresh();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
  },
};
</script>
<style scoped>
.configurationItem{
  display: flex;
  margin-top:10px;
  height: 30px;
  line-height: 30px;
}
.conWords{
  width:190px;
  text-align:right;
}
.conWords2{
  width: 157px;
   text-align:right;
}
.title {
  background: #fff;
  padding: 10px 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.name {
  width: 25%;
}
.screeningBox {
  width: 100%;
  display: flex;
}
.leftBox,
.rightBox {
  width: 50%;
  padding: 0 15px;
  box-sizing: border-box;
}
.leftBox > .leftitem {
  margin-bottom: 15px;
}
.rightBox > .rightitem {
  margin-bottom: 15px;
}
.merchants {
  width: 50%;
}
.merchants1 {
  width: 40%;
}
.widthp30 {
  width: 30%;
}
.store-detail {
  display: flex;
}

.detail-item {
  flex: 1;
}
.statistical {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #00152a;
  color: #fff;
  padding: 12px;
  box-sizing: border-box;
}
.statistical > .statisticalitem {
  width: 50%;
  text-align: center;
  line-height: 200%;
}
.tableBox {
  margin-top: 20px;
}
.store-input {
  width: 95%;
}
.servicename {
  width: 50%;
}
.servicename1 {
  width: 30%;
}
.servicelevel {
  width: 20%;
}
.BDname {
  width: 20%;
}
.red {
  color: #f9607d;
}
.green {
  color: green;
}
.hui {
  color: darkgray;
}
.blue {
  color: blue;
}
.wid100 {
  width: 100%;
  margin-bottom: 20px;
}
.position {
  position: absolute;
  left: 0;
  top: 25px;
  background: #f9607d;
  color: #fff;
  padding: 0;
  width: 18px;
  height: 18px;
  line-height: 20px;
  box-sizing: border-box;
  border-radius: 3px;
}
.greens {
  background: green;
}
</style>